package com.hzkq.widgets;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.keqiang.filepicker.FilePicker;

import androidx.appcompat.app.AppCompatActivity;

public class TestFileChooseActivity extends AppCompatActivity {
    
    private TextView mTvChosenFileDesc;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_file_choose);
        mTvChosenFileDesc = findViewById(R.id.tv_chosen_file_desc);
    }
    
    public void onFileChooseClick(View view) {
        FilePicker.with(this)
            .maxChosenCount(3)
            // .fileExtension("pdf", "excel", "png","jpg")
            // .excludeFileExtension("jpg")
            // .fileMime("text/plain")
            // .excludeFileMime("text/html")
            // .defaultOpenPath(DefaultOpenPath.IMAGE_PATH)
            // .spanCount(6)
            // .preferredLayout(PreferredLayout.GRID)
            // .maxFileSize(500 * 1024)
            .start(files -> {
                if (files == null || files.size() == 0) {
                    mTvChosenFileDesc.setText("未选择任何文件");
                    return;
                }
                
                StringBuilder builder = new StringBuilder("选择了" + files.size() + "个文件：");
                for (int i = 0; i < files.size(); i++) {
                    builder.append("\n\n").append(i + 1).append(".").append(files.get(i).toString());
                }
                mTvChosenFileDesc.setText(builder.toString());
            });
    }
}